package com.dlc.yunguang.adapter.decoration;

import android.content.res.Resources;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by John on 2017/7/11.
 */

public class RecyclerSpace extends RecyclerView.ItemDecoration {

    private int x;
    private int y;

    public RecyclerSpace(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public RecyclerSpace(Resources resources, int xDimenRes, int yDimenRes) {
        if (xDimenRes != 0) {
            this.x = resources.getDimensionPixelOffset(xDimenRes);
        }

        if (yDimenRes != 0) {
            this.y = resources.getDimensionPixelOffset(yDimenRes);
        }
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
        RecyclerView.State state) {

        if (parent.getChildAdapterPosition(view) != 0) {
            outRect.left = x;
            outRect.top = y;
        }
    }
}
